<?php


namespace app\shop\command;


use app\shop\common\consts\RedisKey;
use app\shop\service\chat\ChatVoiceService;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Cache;
use think\facade\Db;

class Hello extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('hello')->setDescription('the hello command');
    }

    protected function execute(Input $input, Output $output)
    {
        $orderIdArr = Db::name('chat_user_new')->column('order_id');

        $orderList = Db::name('order')->whereNotIn('id', $orderIdArr)->limit(10)->select();
        if(!$orderList){
            $output->writeln('no data');
            return;
        }
        foreach ($orderList as $orderInfo) {

            $chatSign = generate_chat_sign($orderInfo['user_id'], 0, $orderInfo['id']);



            $data = [
                'order_id' => $orderInfo['id'],
                'chat_sign' => $chatSign,
                'avatar' => '/avatar/179/66ce72dba667c.png',
                'order_name' => $orderInfo['order_name'],
                'create_time' => time(),
                'update_time' => time(),
            ];
            Db::name('chat_user_new')->insert($data);
            // 最后一条消息
//            $messageModel = Db::name('message')
//                ->where('order_id', $orderInfo['id'])
//                ->whereNotIn('type', ['system', 'event', 'webrtc'])
//                ->order('msg_id', 'desc')
//                ->find();
//            if($messageModel){
//                $chatVoiceService = new ChatVoiceService();
//                $chatVoiceService->setLastMessageToRedis($chatSign, $messageModel['msg_id'], $messageModel['content'], $messageModel['type']);
//            }

            $dataAll = [
                [
                    'chat_sign' => $chatSign,
                    'user_id' => 518,
                    'create_time' => time(),
                    'update_time' => time()
                ],
                [
                    'chat_sign' => $chatSign,
                    'user_id' => $orderInfo['user_id'],
                    'create_time' => time(),
                    'update_time' => time()
                ],
            ];
            if ($orderInfo['design_id']) {
                $dataAll[] = [
                    'chat_sign' => $chatSign,
                    'user_id' => $orderInfo['design_id'],
                    'create_time' => time(),
                    'update_time' => time()
                ];
            }
            Db::name('group_user')->insertAll($dataAll);
        }
        $output->writeln('hello');
    }
}